package com.ctgu.redislock01.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ ClassName RabbitConfig
 * @ Author Alex2
 * @ Date 2025/9/12 16:07
 **/
@Configuration
public class RabbitConfig {

    public static final String QUEUE_USER_UPDATE = "user_update_queue";
    public static final String EXCHANGE_USER_UPDATE = "user_update_exchange";
    public static final String ROUTING_KEY_USER_UPDATE = "user.update";

    @Bean
    public Queue userUpdateQueue() {
        return new Queue(QUEUE_USER_UPDATE, true);
    }

    @Bean
    public DirectExchange userUpdateExchange() {
        return new DirectExchange(EXCHANGE_USER_UPDATE, true, false);
    }

    @Bean
    public Binding bindingProductOrder() {
        return BindingBuilder
                .bind(userUpdateQueue())
                .to(userUpdateExchange())
                .with(ROUTING_KEY_USER_UPDATE);
    }
}